<template>
  <div>
    <p>
      <input
        type="text"
        v-model="username"
        placeholder="输入用户名"
      >
      <input
        type="text"
        v-model="password"
        placeholder="输入密码"
      >
      <button @click="login">登录</button>
    </p>
  </div>
</template>

<script>

export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login() {
      this.axios.post('http://127.0.0.1:8000/login/', { username: this.username, password: this.password }).then((result) => {
        console.log(result)
        var uid = result.data.uid
        var username = result.data.username
        localStorage.uid = uid
        localStorage.username = username
        location.href = '/'
      }).catch((err) => {
        console.log(err)
      });
    }
  }
}
</script>

<style>
</style>